<!DOCTYPE HTML>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="./resources/geometry-interfaces-test-helpers.js"></script>
<script>

test(function() {
  var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
  matrix2d.invertSelf();
  assert_2d_matrix_equals(matrix2d, [-2, 1, 1.5, -0.5, 1, -2]);
}, "DOMMatrix invertSelf() - invertible - 2D matrix");

test(function() {
  var matrix2d = new DOMMatrix([1, 1, 1, 1, 1, 1]);
  matrix2d.invertSelf();
  //when non invertible matrix execute invertSelf(), result matrix is not 2d.
  assert_3d_matrix_equals(matrix2d, [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]);
}, "DOMMatrix invertSelf() - non-invertible - 2D matrix");

test(function() {
  var matrix3d = new DOMMatrix([10, 20, 30, 40, 40, 40, 30, 20, 10, 20, 40, 30, 20, 40, 50, 100]);
  matrix3d.invertSelf();
  assert_matrix_almost_equals(matrix3d, new DOMMatrix([-1.6, 0.05, 0.6, 0.45, 2.05, -0.025, -0.8, -0.575, -0.4, 0, 0.2, 0.1, -0.3, 0, 0.1, 0.1]));
}, "DOMMatrix invertSelf() - 3D matrix");

test(function() {
  var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
  matrix3d.invertSelf();
  assert_3d_matrix_equals(matrix3d, [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]);
}, "DOMMatrix invertSelf() - non-invertible - 3D matrix");
</script>
